"""
    fastapi 生命周期函数
"""


from contextlib import asynccontextmanager

from fastapi import FastAPI

from app.core.tortoise_init import TortoiseProvider


@asynccontextmanager
async def chip_choice_lifespan(app: FastAPI):
    """
    - 启动时初始化数据库等资源
    - 关闭时清理资源
    :param app:
    """
    await TortoiseProvider.init_tortoise(app)
    yield
    await TortoiseProvider.close_tortoise()